package com.yihu.cms.service;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;

import com.yihu.beans.tags.Tags;
import com.yihu.beans.user.User;
import com.yihu.dataService.hessian.mongodb.interfaceService.ArtworkHService;
import com.yihu.dataService.hessian.mongodb.interfaceService.TagsManagerHService;
import com.yihu.dataService.hessian.resource.ResourceMongoDBManager;

public class TagsManagerService {
	
	public List<Tags> getList(String userName)
	{
		List<Tags> l = new ArrayList();
		try {
			TagsManagerHService ths = (TagsManagerHService) ResourceMongoDBManager
					.getSingleton().getBeans("tagsManagerHSC");
			l = ths.getListTags(userName);
		} catch (MalformedURLException e) {
			System.out.println(e.toString());
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		return l;
	}
	
	public int add(Tags tag)
	{
		int result = 0;
		try {
			TagsManagerHService ths = (TagsManagerHService) ResourceMongoDBManager
					.getSingleton().getBeans("tagsManagerHSC");
			result = ths.addTags(tag);
		} catch (MalformedURLException e) {
			result = 1;
			System.out.println(e.toString());
		} catch (IOException e1) {
			result = 2;
			e1.printStackTrace();
		}
		return result;
	}
	
	public int update(Tags tag)
	{
		int result = 0;
		try {
			TagsManagerHService ths = (TagsManagerHService) ResourceMongoDBManager
					.getSingleton().getBeans("tagsManagerHSC");
			result = ths.updateTags(tag);
		} catch (MalformedURLException e) {
			result = 1;
			System.out.println(e.toString());
		} catch (IOException e1) {
			result = 2;
			e1.printStackTrace();
		}
		return result;
	}
	
	public int del(Long id)
	{
		int result = 0;
		try {
			TagsManagerHService ths = (TagsManagerHService) ResourceMongoDBManager
					.getSingleton().getBeans("tagsManagerHSC");
			result = ths.delTags(id);
		} catch (MalformedURLException e) {
			result = 1;
			System.out.println(e.toString());
		} catch (IOException e1) {
			result = 2;
			e1.printStackTrace();
		}
		return result;
	}
	
	public Tags getTagById(Long id)
	{
		Tags tag = null;
		try {
			TagsManagerHService ths = (TagsManagerHService) ResourceMongoDBManager
					.getSingleton().getBeans("tagsManagerHSC");
			tag = ths.getTagById(id);
		} catch (MalformedURLException e) {
//			result = 1;
			System.out.println(e.toString());
		} catch (IOException e1) {
//			result = 2;
			e1.printStackTrace();
		}
		return tag;
	}

}
